home *** CD-ROM | disk | FTP | other *** search
- --------------------------------------------------------------------------------
- -- Weapon Molotov Cocktail + Projectile Molotov Cocktail
- -- Original Carnage Contest Weapon
- -- Script by DC, August 2009, www.UnrealSoftware.de
- --------------------------------------------------------------------------------
-
- -- Setup Tables
- if cc==nil then cc={} end
- cc.cocktail={}
- cc.cocktail.cocktail={}
-
- -- Load & Prepare Ressources
- cc.cocktail.gfx_wpn=loadgfx("weapons/molotovcocktail.png") -- Weapon Image
- setmidhandle(cc.cocktail.gfx_wpn)
- cc.cocktail.sfx_attack=loadsfx("throw.ogg") -- Attack Sound
-
- --------------------------------------------------------------------------------
- -- Weapon: Molotov Cocktail
- --------------------------------------------------------------------------------
-
- cc.cocktail.id=addweapon("cc.cocktail","Molotov Cocktail",cc.cocktail.gfx_wpn,1,2) -- Add Weapon (1 use, first in round 2)
-
- function cc.cocktail.draw() -- Draw
- if weapon_shots<=0 then
- setblend(blend_alpha)
- setalpha(1)
- setcolor(255,255,255)
- drawinhand(cc.cocktail.gfx_wpn,6,0)
- end
- -- HUD chargebar
- if weapon_charge>0 and weapon_shots==0 then
- hudchargebar(weapon_charge,100)
- end
- -- HUD Crosshair
- if weapon_shots==0 then
- hudcrosshair(4,3)
- end
- end
-
- function cc.cocktail.attack(attack) -- Attack
- if (weapon_shots<=0) then
- -- Charge
- if (attack==1) then
- weapon_charge=weapon_charge+1 -- Increase charge
- end
- -- Fire a projectile (on release/full charge)
- if (attack==0 and weapon_charge>0) or (weapon_charge>=100) then
- -- No more weapon switching!
- useweapon(0)
- playsound(cc.cocktail.sfx_attack)
- weapon_shots=weapon_shots+1
- id=createprojectile(cc.cocktail.cocktail.id)
- projectiles[id]={}
- -- Ignore collision with current player at beginning
- projectiles[id].ignore=playercurrent()
- -- Set initial position of projectile
- projectiles[id].x=getplayerx(0)+(4*getplayerdirection(0))+math.sin(math.rad(getplayerrotation(0)))*10.0
- projectiles[id].y=getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*10.0
- -- Set speed of projectile
- projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
- projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
- -- Set timer
- projectiles[id].timer=1
- -- Effects
- recoil(2)
- -- End Turn
- endturn()
- end
- end
- end
-
- --------------------------------------------------------------------------------
- -- Projectile: Molotov Cocktail
- --------------------------------------------------------------------------------
-
- cc.cocktail.cocktail.id=addprojectile("cc.cocktail.cocktail") -- Add Projectile
-
- function cc.cocktail.cocktail.draw(id) -- Draw
- -- Setup draw mode
- setblend(blend_alpha)
- setalpha(1)
- setcolor(255,255,255)
- setscale(1,1)
- -- Calculate projectile rotation
- setrotation(math.deg(math.atan2(math.abs(projectiles[id].sx),-projectiles[id].sy)))
- -- Draw projectile
- drawimage(cc.cocktail.gfx_wpn,projectiles[id].x,projectiles[id].y)
- -- Draw Arrow if out of Screen
- outofscreenarrow(projectiles[id].x,projectiles[id].y)
- end
-
- function cc.cocktail.cocktail.update(id) -- Update
- rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
- -- Particle Tail
- particle(p_smoke,projectiles[id].x,projectiles[id].y)
- particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
- particlefadealpha(0.01)
- particle(p_lightpuff,projectiles[id].x,projectiles[id].y)
- particlefadealpha(0.04)
- if getframe()%3==1 then
- particle(p_spark,projectiles[id].x,projectiles[id].y)
- end
- -- Gravity influence on speed
- projectiles[id].sy=projectiles[id].sy+getgravity()
- -- Move (in substep loop for optimal collision precision)
- msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
- msubx=projectiles[id].sx/msubt
- msuby=projectiles[id].sy/msubt
- for i=1,msubt,1 do
- -- Move X
- projectiles[id].x=projectiles[id].x+msubx
- if collision(col5x5,projectiles[id].x,projectiles[id].y)==1 then
- if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
- projectiles[id].timer=0
- end
- else
- projectiles[id].ignore=0
- end
- -- Move Y
- projectiles[id].y=projectiles[id].y+msuby
- if collision(col5x5,projectiles[id].x,projectiles[id].y)==1 then
- if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
- projectiles[id].timer=0
- end
- else
- projectiles[id].ignore=0
- end
- -- Water
- if (projectiles[id].y)>getwatery()+5 then
- -- Effects
- particle(p_waterhit,projectiles[id].x,projectiles[id].y)
- playsound(sfx_hitwater1)
- -- Free projectile
- freeprojectile(id)
- break
- end
- end
- -- Explode
- if projectiles[id].timer<=0 then
- -- Cause damage
- arealdamage(projectiles[id].x,projectiles[id].y,100,15)
- -- Destroy terrain
- terrainexplosion(projectiles[id].x,projectiles[id].y,15,1)
- -- Crater
- grey=math.random(0,40)
- if math.random(0,1)==1 then
- terrainalphaimage(gfx_crater100,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
- else
- terrainalphaimage(gfx_crater125,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
- end
- -- Fire
- createobject(o_fire,projectiles[id].x,projectiles[id].y)
- for a=45,360,45 do
- createobject(o_fire,projectiles[id].x+math.sin(math.rad(a))*35,projectiles[id].y-math.cos(math.rad(a))*35)
- end
- -- Free projectile
- freeprojectile(id)
- end
- -- Scroll to projectile
- scroll(projectiles[id].x,projectiles[id].y)
- end